// Device/pages/Bind/List/index.js
import {
    deviceBindList
} from '@/entries/index';
import { customNavigate } from '@/utils/route'
const app = getApp();
Page({
    data: {
        staticPrefix: app.globalData.STATIC_PREFIX,
        list: [],
        sidebarIndex: 0,
        scrollTop: 0
    },
    onLoad(options) {
        this.setData({
            list: deviceBindList
        }, () => {
            setTimeout(() => {
                const query = this.createSelectorQuery()
                query.selectAll('.list-item')
                    .boundingClientRect((rects) => {
                    })
                    .exec()
            }, 1000)
        })
    },
    onListScroll(e) {
        const that = this;
        const query = this.createSelectorQuery()
        query.selectAll('.list-item')
            .boundingClientRect((rects) => {
                if (rects[1].top < 150) {
                    that.setData({
                        sidebarIndex: 1
                    })
                } else {
                    that.setData({
                        sidebarIndex: 0
                    })
                }
            })
            .exec()
    },
    onMenuItemTap(e) {
        const index = e.currentTarget.dataset.index;
        this.setData({
            sidebarIndex: index,
            scrollTop: index * 1000
        });
    },
    onTapItem(e) {
        const { item } = e.currentTarget.dataset;
        // 未上线项目无法进入流程
        if(!item.is_online) return;
        const params = {
            ...item
        }
        customNavigate({
            url: '/Device/pages/Bind/Explain/index',
            params
        })
    }
})